package com.hk.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.hk.mapper.DictDataMapper;
import com.hk.model.pojo.SysDictData;
import com.hk.result.PageResult;
import com.hk.service.DictDataService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@Slf4j
public class DictDataServiceImpl extends ServiceImpl<DictDataMapper, SysDictData> implements DictDataService {

    /**
     * 查询活动类型
     *
     * @return
     */
    @Override
    public List<SysDictData> getChannelList() {
        LambdaQueryWrapper<SysDictData> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(SysDictData::getDictType, "channel_type");
        List<SysDictData> list = super.list(wrapper);
        return list;
    }

    /**
     * 获取线索跟进项
     *
     * @return
     */
    @Override
    public List<SysDictData> getCluesItem() {
        LambdaQueryWrapper<SysDictData> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(SysDictData::getDictType, "clues_item");
        List<SysDictData> list = super.list(wrapper);
        return list;

    }

    /**
     * 活动状态
     *
     * @return
     */
    @Override
    public List<SysDictData> getActivityStatus() {
        LambdaQueryWrapper<SysDictData> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(SysDictData::getDictType, "activity_status");
        List<SysDictData> list = super.list(wrapper);
        return list;

    }


    @Autowired
    private DictDataMapper dictDataMapper;

    /**
     * 查询字典数据
     *
     * @return
     */
    @Override
    public List<SysDictData> getNormalDisable() {
        return dictDataMapper.selectList(new LambdaQueryWrapper<SysDictData>().eq(SysDictData::getDictType, "sys_normal_disable"));
    }

    /**
     * 新增字典数据
     *
     * @param sysDictData
     */
    @Override
    public void addDictData(SysDictData sysDictData) {
        dictDataMapper.insert(sysDictData);
    }

    /**
     * 分页查询字典数据
     */
    @Override
    public PageResult selectDictDataByPage(Integer pageNum, Integer pageSize, String dictName, String dictType, Integer status, String beginTime, String endTime) {
        PageHelper.startPage(pageNum, pageSize);

        Page<SysDictData> dataByPage = dictDataMapper.selectDictDataByPage(dictName, dictType, status, beginTime, endTime);
        return new PageResult(dataByPage.getTotal(), dataByPage.getResult());
    }

    /**
     * 根据id查询字典数据
     *
     * @param id
     * @return
     */
    @Override
    public SysDictData getDictDataById(Long id) {
        return dictDataMapper.selectDictDataById(id);
    }

    /**
     * 修改字典数据
     *
     * @param sysDictData
     */
    @Override
    public void updateDictData(SysDictData sysDictData) {
        dictDataMapper.updateDictDataById(sysDictData);
    }

    /**
     * 批量删除字典数据
     *
     * @param ids
     */
    @Override
    public void deleteDictData(Long[] ids) {
        dictDataMapper.deleteBatchCodes(ids);
    }

    /**
     * 查询课程字典数据
     *
     * @return
     */
    @Override
    public List<SysDictData> getCourseSubject() {
        List<SysDictData> list = dictDataMapper.selectList(new LambdaQueryWrapper<SysDictData>().eq(SysDictData::getDictType, "course_subject"));
        return list;
    }

    /**
     * 查询适用人群
     *
     * @return
     */
    @Override
    public List<SysDictData> getApplicablePerson() {
        return dictDataMapper.selectList(new LambdaQueryWrapper<SysDictData>().eq(SysDictData::getDictType, "applicable_person"));
    }

    /**
     * 查询线索等级
     *
     * @return
     */
    @Override
    public List<SysDictData> getCluesLevel() {
        return dictDataMapper.selectList(new LambdaQueryWrapper<SysDictData>().eq(SysDictData::getDictType, "clues_level"));
    }

    /**
     * 查询跟进状态
     *
     * @return
     */
    @Override
    public List<SysDictData> getFollowStatus() {
        return dictDataMapper.selectList(new LambdaQueryWrapper<SysDictData>().eq(SysDictData::getDictType, "clue_status"));
    }

    /**
     * 查询回收时限
     *
     * @return
     */
    @Override
    public List<SysDictData> getRecycleTime() {
        return dictDataMapper.selectList(new LambdaQueryWrapper<SysDictData>().eq(SysDictData::getDictType, "recycle_time"));
    }

    /**
     * 查询预警时间
     *
     * @return
     */
    @Override
    public List<SysDictData> getWarnTime() {
        return dictDataMapper.selectList(new LambdaQueryWrapper<SysDictData>().eq(SysDictData::getDictType, "warn_time"));
    }

    /**
     * 查询重复捞取时间限制
     *
     * @return
     */
    @Override
    public List<SysDictData> getLimitTime() {
        return dictDataMapper.selectList(new LambdaQueryWrapper<SysDictData>().eq(SysDictData::getDictType, "limit_time"));
    }

    /**
     * 查询性别
     *
     * @return
     */
    @Override
    public List<SysDictData> getSex() {
        return dictDataMapper.selectList(new LambdaQueryWrapper<SysDictData>().eq(SysDictData::getDictType, "sys_user_sex"));
    }

}
